* **************************************************************************** *
* Sierra Leone - Social Signaling and Childhood Immunization
* The Effect of Signals on Preferences for Different Vaccinations
* **************************************************************************** *
/*
** Purpose:    Table: The Effect of Signals on Preferences for Different Vaccinations

*/
* **************************************************************************** *
* **************************************************************************** *


	use  "${Replicate_SocialSignals_dtaInter}/Endline_Survey_Data.dta", clear

	* merge the ANC treatment status:
	merge m:m clinic  using  "${Replicate_SocialSignals_dtaInter}/MasterData_PilotClinics.dta", gen(ANCtreat)


	* label variables
	lab var treat2 "Uninformative Bracelet"
	lab var treat3 "Signal at 4"
	lab var treat4 "Signal at 5"

	foreach num of numlist 1(1)5 {
		lab var vacc_important`num' "Vaccine `num'"
	}
	
	lab var vacc_important6 "All vaccines"


	* Generate the controls for the the two new columns:
	tab    arm_anc, gen(anc)

	* most important
	foreach var in anc2 anc3 anc4 {
		sum  `var'                                   if vacc_important1 !=.  & intervention_arm==1, detail
		gen  `var'_most_dm    = `var' - `r(mean)'      if vacc_important1 !=.
	}

	* second most important:
	foreach var in anc2 anc3 anc4 {
		sum  `var'                                   if vacc_important21 !=.  & intervention_arm==1, detail
		gen  `var'_second_dm    = `var' -  `r(mean)'     if vacc_important21 !=.
	}


	**PANEL A: Most Important Vaccine

	local  ANC_most_dm   = " anc2_most_dm anc3_most_dm anc4_most_dm "
	local  ANC_second_dm = " anc2_second_dm anc3_second_dm anc4_second_dm "

	eststo clear
	foreach vaccine of numlist 1(1)6   {

		areg       vacc_important`vaccine' treat3 treat4 treat2   `ANC_most_dm', absorb(strata) vce(bootstrap, reps(${RepsNum}) seed(${seed}) cluster(clinic))
		test   treat2 = treat4
		estadd scalar treat2_treat4 = r(p)
		test   treat2 = treat3
		estadd scalar treat2_treat3 = r(p)
		test   treat3 = treat4
		estadd scalar treat3_treat4 = r(p)
		test   treat2 treat3 treat4
		estadd scalar bracelets     = r(p)
		estadd scalar C_mean        = _b[_cons]
		estadd local  Obs           = "`e(N)'"
		eststo m_vacc_important`vaccine'
	}

	esttab  ///
	m_vacc_important1 m_vacc_important2 m_vacc_important3                 ///
	m_vacc_important4 m_vacc_important5 m_vacc_important6                 ///
	using "${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations_new.tex",        ///
	refcat(treat3 "\hline \multicolumn{1}{l}{\textbf{\textit{Panel A:}}} & \multicolumn{6}{c}{Most Important Vaccine} \\ \hline %", nolabel) ///
	prehead("\begin{tabular}{l*{7}{c}} \toprule"                  ///
	"\multicolumn{1}{l}{\textbf{Dependent variable:}} & \multicolumn{1}{c}{\textbf{Vaccine 1}} & \multicolumn{1}{c}{\textbf{Vaccine 2}} & \multicolumn{1}{c}{\textbf{Vaccine 3}} & \multicolumn{1}{c}{\textbf{Vaccine 4}} & \multicolumn{1}{c}{\textbf{Vaccine 5}} & \multicolumn{1}{c}{\textbf{All vaccines}} \\")  ///
	drop(_cons anc*)     ///
	scalars("C_mean       Control Group mean"        ///
	"Obs          Observations"                                   ///
	"treat2_treat3 \(S_{4}\) \(>\) 0: p(UI = S4)"                 ///
	"treat2_treat4 \(S_{5}\) \(>\) 0: p(UI = S5)"                 ///
	"treat3_treat4 p(S4 = S5)"                                    ///
	"bracelets Joint F-Test")                                     ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))                ///
	sfmt(3) b(3) se(3)  ${StarsOpt}                                       ///
	fragment nogaps nomtitles label noobs nolines                         ///
	replace


	**PANEL B: Second Most Important Vaccine
	foreach vaccine of numlist 1(1)6   {

		areg       vacc_important2`vaccine'  treat3 treat4 treat2   `ANC_second_dm', absorb(strata) vce(bootstrap, reps(${RepsNum}) seed(${seed}) cluster(clinic))
		test   treat2 = treat4
		estadd scalar treat2_treat4 = r(p)
		test   treat2 = treat3
		estadd scalar treat2_treat3 = r(p)
		test   treat3 = treat4
		estadd scalar treat3_treat4 = r(p)
		test   treat2 treat3 treat4
		estadd scalar bracelets     = r(p)
		estadd scalar C_mean        = _b[_cons]
		estadd local  Obs           = "`e(N)'"
		eststo m_vacc_important2`vaccine'
	}

	esttab   ///
	m_vacc_important21 m_vacc_important22 m_vacc_important23              ///
	m_vacc_important24 m_vacc_important25 m_vacc_important26              ///
	using "${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations_new.tex",        ///
	refcat(treat3 "\hline \multicolumn{1}{l}{\textbf{\textit{Panel B:}}}  & \multicolumn{6}{c}{Second Most Important Vaccine} \\ \hline %", nolabel) ///
	drop(_cons anc*)     ///
	scalars("C_mean       Control Group mean"        ///
	"Obs          Observations"                                   ///
	"treat2_treat3 \(S_{4}\) \(>\) 0: p(UI = S4)"                 ///
	"treat2_treat4 \(S_{5}\) \(>\) 0: p(UI = S5)"                 ///
	"treat3_treat4 p(S4 = S5)"                                    ///
	"bracelets Joint F-Test")                                     ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))                ///
	sfmt(3) b(3) se(3)  ${StarsOpt}                                       ///
	fragment append nomtitles noobs nonumbers nolines                     ///
	postfoot("\bottomrule \end{tabular}")                                 ///
	label


	filefilter "${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations_new.tex"      ///
	"${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations.tex", from("[1em]") to(" ") replace
	erase	    "${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations_new.tex"



	* ----------------------------------------------------------------------------
	* outsheet p-values, with controls


	esttab  ///
	m_vacc_important1 m_vacc_important2 m_vacc_important3                 ///
	m_vacc_important4 m_vacc_important5 m_vacc_important6                 ///
	using "${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations_new.tex",        ///
	refcat(treat3 "\hline \multicolumn{1}{l}{\textbf{\textit{Panel A:}}} & \multicolumn{6}{c}{Most Important Vaccine} \\ \hline %", nolabel) ///
	prehead("\begin{tabular}{l*{7}{c}} \toprule"                  ///
	"\multicolumn{1}{l}{\textbf{Dependent variable:}} & \multicolumn{1}{c}{\textbf{Vaccine 1}} & \multicolumn{1}{c}{\textbf{Vaccine 2}} & \multicolumn{1}{c}{\textbf{Vaccine 3}} & \multicolumn{1}{c}{\textbf{Vaccine 4}} & \multicolumn{1}{c}{\textbf{Vaccine 5}} & \multicolumn{1}{c}{\textbf{All vaccines}} \\")  ///
	drop(_cons anc*)     ///
	scalars("C_mean       Control Group mean"        ///
	"Obs          Observations"                                   ///
	"treat2_treat3 \(S_{4}\) \(>\) 0: p(UI = S4)"                 ///
	"treat2_treat4 \(S_{5}\) \(>\) 0: p(UI = S5)"                 ///
	"treat3_treat4 p(S4 = S5)"                                    ///
	"bracelets Joint F-Test")                                     ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))                ///
	sfmt(3) b(3) p(3)  ${StarsOpt}                                       ///
	fragment nogaps nomtitles label noobs nolines                         ///
	replace


	esttab   ///
	m_vacc_important21 m_vacc_important22 m_vacc_important23              ///
	m_vacc_important24 m_vacc_important25 m_vacc_important26              ///
	using "${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations_new.tex",        ///
	refcat(treat3 "\hline \multicolumn{1}{l}{\textbf{\textit{Panel B:}}}  & \multicolumn{6}{c}{Second Most Important Vaccine} \\ \hline %", nolabel) ///
	drop(_cons anc*)     ///
	scalars("C_mean       Control Group mean"        ///
	"Obs          Observations"                                   ///
	"treat2_treat3 \(S_{4}\) \(>\) 0: p(UI = S4)"                 ///
	"treat2_treat4 \(S_{5}\) \(>\) 0: p(UI = S5)"                 ///
	"treat3_treat4 p(S4 = S5)"                                    ///
	"bracelets Joint F-Test")                                     ///
	substitute(\(S\_{4}\) \(S_{4}\)  \(S\_{5}\) \(S_{5}\))                ///
	sfmt(3) b(3) p(3)  ${StarsOpt}                                       ///
	fragment append nomtitles noobs nonumbers nolines                     ///
	postfoot("\bottomrule \end{tabular}")                                 ///
	label


	filefilter "${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations_new.tex"      ///
	"${Replicate_SocialSignals_Tables}/pvalues/Table_PreferencesVaccinations_pvals.tex", from("[1em]") to(" ") replace
	erase	     "${Replicate_SocialSignals_Tables}/Table_PreferencesVaccinations_new.tex"




* **************************************************************************** *
* End of the Do file !!!
* **************************************************************************** *
